package com.rabc.web.controller;

import com.core.base.BaseController;
import com.rabc.web.annotation.Loggable;
import com.rabc.web.entity.SysDict;
import com.rabc.web.service.SysDictService;
import com.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Api(tags = "数据字典管理")
@RestController
@RequestMapping("/sysDict")
public class SysDictController extends BaseController {


    @Autowired
    private SysDictService sysDictService;




    @Loggable()
    @ApiOperation("查询字典列表")
    @GetMapping("/list")
    public R list(SysDict sysDict) {
        List<SysDict> list = sysDictService.selectDictList(sysDict);
        return R.success(list);
    }

    @ApiOperation("根据ID查询字典")
    @GetMapping("/{id}")
    public R getInfo(@PathVariable Long id) {
        SysDict sysDict = sysDictService.getById(id);
        return R.success(sysDict);
    }

    @Loggable()
    @ApiOperation("新增字典")
    @PostMapping("/add")
    public R add(@RequestBody SysDict sysDict) {
        boolean success = sysDictService.save(sysDict);
        return success ? R.success() : R.error();
    }

    @ApiOperation("修改字典")
    @PutMapping("/edit")
    public R edit(@RequestBody SysDict sysDict) {
        boolean success = sysDictService.updateById(sysDict);
        return success ? R.success() : R.error();
    }

    @ApiOperation("删除字典")
    @DeleteMapping("/{id}")
    public R remove(@PathVariable Long id) {
        boolean success = sysDictService.removeById(id);
        return success ? R.success() : R.error();
    }
}
